using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace WindowsGame4
{
    public class WaveGun : Weapon
    {
        public Vector2 begin, end;
        public Projectile wave;
        public WaveGun(Player owner)
            : base(owner)
        {
        }
        public override void BeginFire(Vector2 target)
        {
            wave = new Projectile();
            wave.bCollides = false;
            wave.texture = GameManager.pixel;
            wave.color = new Vector4(0, 1, 0, 1);
            GameManager.AddObject(wave);
            base.BeginFire(target);
        }
        public override void Fire(Vector2 target)
        {
            base.Fire(target);
            Vector2 dir = end - begin;
            wave.angle = GetAngle(dir);
            wave.scale = new Vector2(dir.Length(), 1);
            wave.pos = (begin+end)*.5f;
        }
        public override void EndFire(Vector2 target)
        {
            Vector2 dir = begin - end;
            float waveLength = dir.Length();
            if (dir.Length()>0)
                dir.Normalize();
            Vector2 norm = new Vector2(dir.Y, -dir.X);
            norm *= Math.Sign(Vector2.Dot(norm, begin - pos));
            wave.bCollides = true;
            wave.bBlocks = false;
            wave.bDieOnHit = false;
            wave.hit = Projectile.HitType.Enemy;
            wave.damage = waveLength;
            wave.vel = norm * 300;
            wave.bOntimer = true;
            wave.lifeTime = 3;
            base.EndFire(target);
        }
    }
}
